home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 August (Alt) / CHIP 2005-08.1.iso / program / guvenlik / syslinux-3.07.exe / sample / hello2.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-14  |  1.5 KB  |  62 lines

  1. #ident "$Id: hello2.c,v 1.4 2004/12/14 22:46:25 hpa Exp $"
  2. /* ----------------------------------------------------------------------- *
  3.  *   
  4.  *   Copyright 2002 H. Peter Anvin - All Rights Reserved
  5.  *
  6.  *   This program is free software; you can redistribute it and/or modify
  7.  *   it under the terms of the GNU General Public License as published by
  8.  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
  9.  *   Boston MA 02111-1307, USA; either version 2 of the License, or
  10.  *   (at your option) any later version; incorporated herein by reference.
  11.  *
  12.  * ----------------------------------------------------------------------- */
  13.  
  14. /*
  15.  * hello2.c
  16.  *
  17.  * Simple COM32 image
  18.  *
  19.  * This version shows how to use the bounce buffer for data transfer
  20.  * to the BIOS or COMBOOT system calls.
  21.  */
  22.  
  23. #include <com32.h>
  24.  
  25. #define NULL ((void *)0)
  26.  
  27. static inline void memset(void *buf, int ch, unsigned int len)
  28. {
  29.   asm volatile("cld; rep; stosb"
  30.            : "+D" (buf), "+c" (len) : "a" (ch) : "memory");
  31. }
  32.  
  33. static void strcpy(char *dst, const char *src)
  34. {
  35.   while ( *src )
  36.     *dst++ = *src++;
  37.  
  38.   *dst = '\0';
  39. }
  40.  
  41. static void writemsg(const char *msg)
  42. {
  43.   com32sys_t inreg;
  44.  
  45.   memset(&inreg, 0, sizeof inreg);
  46.  
  47.   strcpy(__com32.cs_bounce, msg);
  48.   inreg.eax.w[0] = 0x0002;    /* Write string */
  49.   inreg.ebx.w[0] = OFFS(__com32.cs_bounce);
  50.   inreg.es       = SEG(__com32.cs_bounce);
  51.   __com32.cs_intcall(0x22, &inreg, NULL);
  52. };  
  53.  
  54. int __start(void)
  55. {
  56.   writemsg("Hello, World!\r\n"
  57.        "cmdline = ");
  58.   writemsg(__com32.cs_cmdline);
  59.   writemsg("\r\n");
  60.   return 0;
  61. }
  62.